package com.wjb.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : 王济彬
 * @date: 2025/5/28 - 05 - 28 - 13:16
 * @Description: com.wjb.config
 * @version: 1.0
 */
@Configuration
public class CouponClientExchangeConfig {
    public static final String CPUPON_EXCHANGE = "coupon_exchange";
    public static final String CPUPON_ROUTING_KEY = "coupon_routing_key";
    public static final String CPUPON_QUEUE = "coupon_queue";

    @Bean
    public Queue couponClientQueue() {
        return QueueBuilder.durable(CPUPON_QUEUE).build();
    }

    //延迟交换机
    @Bean
    public Exchange couponClientExchange() {
        Map<String,Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type","topic");
        Exchange exchange = new CustomExchange(CPUPON_EXCHANGE,"x-delayed-message",true,false,arguments);
        return exchange;
    }

    @Bean
    public Binding couponClientBinding() {
        return BindingBuilder.bind(couponClientQueue()).to(couponClientExchange()).with(CPUPON_ROUTING_KEY).noargs();
    }
}
